package br.com.sig.presentation.converter;

import java.io.Serializable;

import javax.enterprise.context.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
  
/** 
* Converter para inputs em geral.
*/
@FacesConverter(value = "inputConverter")
@RequestScoped
public class InputConverter implements Converter, Serializable {

	private static final long serialVersionUID = 4659111447769731711L;

	public Object getAsObject(FacesContext ctx, UIComponent component,  
            String value) { 
		
        if (value != null && !value.trim().isEmpty()) {
            return value.replaceAll("[- . /]", "").replaceAll("[-()]", "");
        }
		
        return null;
    }  
  
    public String getAsString(FacesContext ctx, UIComponent component,  
            Object value) {
    	return value != null ? value.toString() : null;
    }
}